package com.kimo.shop.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kimo.shop.bean.model.RefundAddr;
import com.kimo.shop.dao.RefundAddrMapper;
import com.kimo.shop.service.RefundAddrService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * @author kimo-taozhouchuan
 * @date 2019-06-28 10:19:21
 */
@Service
@AllArgsConstructor
public class RefundAddrServiceImpl extends ServiceImpl<RefundAddrMapper, RefundAddr> implements RefundAddrService {

    private RefundAddrMapper refundAddrMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRefundAddr(RefundAddr refundAddr) {
        if (Objects.equals(refundAddr.getDefaultAddr(), 1)) {
            refundAddrMapper.cancelDefaultAddr(refundAddr.getShopId());
        }
        refundAddrMapper.insert(refundAddr);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRefundAddr(Long shopId, RefundAddr refundAddr) {
        if (Objects.equals(refundAddr.getDefaultAddr(), 1)) {
            refundAddrMapper.cancelDefaultAddr(shopId);
        }
        refundAddrMapper.updateById(refundAddr);
    }
}
